#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int maxTotalReward(vector<int>& a) {
    sort(a.begin(), a.end());
    int m = a.back();
    vector<bool> f(2 * m);
    f[0] = true;
    for (auto x : a)
        for (int j = 2 * x - 1; j >= x; j--)
            if (f[j - x])
                f[j] = true;
    int res = 0;
    for (int i = 0; i < f.size(); i++)
        if (f[i])
            res = i;
    return res;
}